local thbattle__qinxin_xiwang = fk.CreateSkill {

  name = "thbattle__qinxin_xiwang",

  tags = {  },

}

Fk:addPoxiMethod {
  name = "thbattle__qinxin_xiwang_getcards",
  card_filter = function(to_select, selected, data)
    if #data[2] == 0 then
      return true
    else
      local suit = Fk:getCardById(data[2][1]).suit
      return Fk:getCardById(to_select).suit == suit
    end
  end,
  feasible = function(selected)
    return true
  end,
}

thbattle__qinxin_xiwang:addEffect(fk.EventPhaseStart, {
  prompt = "#thbattle__qinxin_xiwang",
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(thbattle__qinxin_xiwang.name) and player.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(1 + player.maxHp - player.hp)
    local array_cards = room:askForArrangeCards(player, thbattle__qinxin_xiwang.name, { cards, "Top", "toObtain" }
      , "#thbattle__qinxin_xiwang-arrange:::" .. #cards, true, nil,
      { 1 + player.maxHp - player.hp, 1 + player.maxHp - player.hp },
      { 0, 0 }, ".", "thbattle__qinxin_xiwang_getcards"
      , { {}, { cards[1] } })
    room:showCards(array_cards[2])
    room:obtainCard(player, array_cards[2], false, fk.ReasonPrey, player, thbattle__qinxin_xiwang.name)
    if #array_cards[1] > 0 then
      for i, cid in ipairs(array_cards[1]) do
        table.remove(room.draw_pile, i)
        table.insert(room.draw_pile, i, cid)
      end
    end
  end
})

return thbattle__qinxin_xiwang